<%--
  Created by IntelliJ IDEA.
  User: q
  Date: 2021/11/15
  Time: 18:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>restful</title>
    <script src="js/jquery-3.4.1.min.js"></script>
    <script>
        $(function () {
            //alert("111")
            $("#findAllBtn").click(function () {
                $.get('/user/findAll', null, function (result) {
                    console.log(result);
                },'json')
            })

            $("#findByIdBtn").click(function () {
                $.get('/user/findById/10', null, function (result) {
                    console.log(result)
                },'json')
            })

            $("#deleteBtn").click(function () {
                $.ajax({
                    url : '/user/delete/20',
                    type : 'delete',
                    dataType : 'json',
                    success : function (result) {
                        console.log(result)
                    },
                    error : function () {
                        alert("error...")
                    }
                })
            })

            var user = {
                userId : 10,
                username : 'tom',
                password : '123456',
                gender : 1,
                birth: new Date()
            }

            $("#putBtn").click(function () {
                $.ajax({
                    url : '/user/update',
                    type: 'put',
                    contentType : 'application/json;charset=UTF-8',
                    data : JSON.stringify(user),
                    dataType: 'json',
                    success : function (result) {
                        console.log(result)
                    },
                    error : function () {
                        alert('error...')
                    }
                })
            })

            $("#postBtn").click(function () {
                $.ajax({
                    url : '/user/save',
                    type : 'post',
                    contentType: 'application/json;charset=UTF-8',
                    data: JSON.stringify(user),
                    dataType: 'json',
                    success: function (result) {
                        console.log(result)
                    },
                    error : function () {
                        alert('error...')
                    }
                })
            })

        })
    </script>
</head>
<body>

    <input id="findAllBtn" type="button" value="查询所有用户[GET]"/>
    <br/><br/>

    <input id="findByIdBtn" type="button" value="根据ID查询用户[GET]"/>
    <br/><br/>

    <input id="deleteBtn" type="button" value="根据ID删除用户[DELETE]"/>
    <br/><br/>

    <input id="putBtn" type="button" value="更新用户[PUT]"/>
    <br/><br/>

    <input id="postBtn" type="button" value="增加用户[POST]"/>

</body>
</html>
